home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / indtline.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  4.4 KB  |  159 lines

  1. ;void  indent_line(strg,printer_codes,margin);
  2. ;  char  *strg,*printer_codes;
  3. ;  unsigned short  margin;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _time_out:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC  _indent_line
  12. _indent_line proc near
  13.     jmp  short start    ;jmp over local data
  14. delay    dw   ?            ;
  15. target  dw   ?            ;
  16. start:    push bp            ;
  17.     mov  bp,sp        ;
  18.     push di            ;
  19.     push si            ;
  20.     cmp  _memory_model,0    ;near or far?
  21.     jle  begin        ;jump if near
  22.     inc  bp            ;else add 2 to BP
  23.     inc  bp            ;
  24. begin:    push ds            ;
  25.     mov  ah,1        ;BIOS func to init prtr
  26.     sub  dx,dx        ;choose LPT1
  27.     int  17h        ;initialize the prtr port
  28.     sub  ax,ax        ;clear AX
  29.     mov  es,ax        ;point ES to 0000:0000
  30.     mov  dx,es:[408h]    ;get LPT1 base address
  31.     mov  _error_code,1    ;1 = printer error
  32.     mov  al,_time_out    ;get _time_out seconds
  33.     cmp  _memory_model,2    ;data near or far?
  34.     jb   A1            ;jump if near
  35.     les  di,dword ptr[bp+4] ;ES:DI pts to Strg
  36.     lds  si,dword ptr[bp+8] ;DS:SI pts to PrinterCodes
  37.     add  bp,4        ;add 4 to BP since dword ptrs
  38.     jmp  short B1        ;
  39. A1:    mov  si,[bp+6]        ;NEAR case
  40.     push ds            ;
  41.     pop  es            ;
  42.     mov  di,[bp+4]        ;
  43. B1:    or   al,al        ;don't allow zero seconds
  44.     jnz  C1            ;
  45.     mov  al,3        ;default to 3 seconds
  46. C1:    mov  cl,18        ;18 ticks per second
  47.     mul  cl            ;
  48.     mov  cs:delay,ax    ;save count
  49.     sub  cx,cx        ;clear CX
  50.     mov  cl,[bp+8]        ;margin (255 chars max)
  51.     jcxz E1            ;jump if zero margin
  52. D1:    mov  al,' '        ;write space char
  53.     call Writeit        ;go write it
  54.     or   ah,ah        ;check for error
  55.     jz   M1            ;quit if printer error
  56.     loop D1            ;do next char in margin
  57. E1:    cmp  byte ptr es:[di],0    ;null string?
  58.     je   L1            ;go do CR-LF if null
  59. F1:    mov  al,es:[di]        ;get a character
  60.     inc  di            ;forward Strg ptr for next time
  61.     cmp  al,0        ;end of string?
  62.     je   L1            ;
  63.     cmp  al,128        ;test if control code
  64.     jb   J1            ;jump if below range
  65.     cmp  al,159        ;test if above
  66.     ja   J1            ;jump if above
  67.     push cx            ;save Strg len ctr
  68.     push si            ;copy PrinterCodes ptr
  69.     sub  al,128        ;count codes from 0
  70.     mov  cl,6        ;times six bytes
  71.     mul  cl            ;offset in PrinterCodes
  72.     add  si,ax        ;SI pts to code sequence
  73.     sub  cx,cx        ;clear CX
  74.     mov  cl,[si]        ;get string descriptor
  75.     jcxz I1            ;quit loop if null
  76. G1:    inc  si            ;forward ptr
  77.     mov  al,[si]        ;get code character
  78.     call Writeit        ;write the code
  79.     or   ah,ah        ;printer error?
  80.     jnz  H1            ;continue if not
  81.     pop  cx            ;balance stack
  82.     pop  cx            ;again
  83.     jmp  short M1        ;quit routine
  84. H1:    loop G1            ;go do next
  85. I1:    pop  si            ;prior Printercodes ptr
  86.     pop  cx            ;restore Strg len ctr
  87.     jmp  short K1        ;go get next char in Strg
  88. J1:    call Writeit        ;go write character
  89.     or   ah,ah        ;proc returned error?
  90.     jz   M1            ;quit if so
  91. K1:    jmp  short F1        ;loop
  92. L1:    mov  al,13        ;CR
  93.     call Writeit        ;print it
  94.     or   ah,ah        ;test for error
  95.     jz   M1            ;quit if error
  96.     mov  al,10        ;LF
  97.     call Writeit        ;print it
  98.     or   ah,ah        ;test for error
  99.     jz   M1            ;quit if error
  100.     mov  al,1        ;success return code
  101.     pop  ds            ;
  102.     mov  _error_code,0    ;0 = no error
  103.     jmp  short N1        ;
  104. M1:    pop  ds            ;
  105. N1:    pop  si            ;
  106.     pop  di            ;
  107.     pop  bp            ;
  108.     cmp  _memory_model,0    ;quit
  109.     jle  quit        ;
  110.     db   0CBh        ;RET far
  111. quit:    ret            ;RET near
  112. Writeit    PROC
  113.     out  dx,al        ;send to output data register
  114.     inc  dx            ;forward to status register
  115.     push cx            ;save string counter
  116.     call GetBiosCount    ;get timer reading
  117.     mov  bx,cx        ;make copy
  118.     add  cx,cs:delay    ;add delay count
  119.     cmp  bx,cx        ;if timer doesn't turn over...
  120.     jb   O1            ;go ahead
  121.     mov  cx,cs:delay    ;otherwise, extend delay
  122. O1:    mov  cs:target,cx    ;save target count
  123. Wait:    in   al,dx        ;get status value
  124.     test al,8        ;test for printer error
  125.     jz   Error        ;
  126.     test al,80h        ;test for Printer Ready
  127.     jnz  Ready        ;jump if ready
  128. Error:    call GetBiosCount    ;
  129.     cmp  cx,cs:target    ;compare to target
  130.     jb   Wait        ;    
  131.     mov  bl,1        ;1 = error
  132.     pop  cx            ;restore string counter
  133.     mov  ah,0        ;return code for failure
  134.     jmp  short P1        ;return
  135. Ready:    pop  cx            ;restore string counter
  136.     inc  dx            ; output control register
  137.     mov  al,13        ;bits for strobe signal
  138.     out  dx,al        ;send the signal
  139.     dec  al            ;change to strobe OFF
  140.     out  dx,al        ;send the signal
  141.     dec  dx            ;point back to
  142.     dec  dx            ;  base address
  143.     mov  ah,1        ;return code for success
  144. P1:    ret              ;
  145. Writeit    endp
  146. GetBIOSCount PROC
  147.     push dx            ;return value in CX:DX
  148.     push ax            ;
  149.     sub  ah,ah        ;function number
  150.     int  1ah        ;get timer count
  151.     mov  cx,dx        ;low word in CX
  152.     pop  ax            ;
  153.     pop  dx
  154.     ret
  155. GetBIOSCount endp
  156. _indent_line endp
  157. _TEXT    ENDS
  158.     END
  159.